package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.setVipChannelBean;
import com.ymatou.iapi.godmch.service.createmchCall;
import com.ymatou.iapi.godmch.service.setVipChannelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
/**
*设置vip渠道商标识
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setVipChannel{
	private static setVipChannelBean bean;
	private static setVipChannelCall call;
	
	private static mch_infoWapper mchInfoWapper = new mch_infoWapper();
	private static mch_relationWapper mchrelationWapper = new mch_relationWapper();
	private static agent_typeWapper agenttypeWapper = new agent_typeWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置vip渠道商标识");
	}

	@Before
	public void caseUp() {
		bean=new setVipChannelBean();
		call=new setVipChannelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setVipChannel_001() {
		Logger.start(true,"正例-设置vip渠道商标识-没有代理");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			bean.setMchId(mchId);
			bean.setVipFlag(true);
			call.setData(bean);
			call.callService();			
			//mch_info
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			Logger.verifyEquals(1, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip=1");
			// agent_type
			Map<String, Object> map2 = new HashMap();
			map2.put("mchId", mchId);
			List<agent_type> agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setVipChannel_002() {
		Logger.start(true,"正例-设置vip渠道商标识-渠道-创建代理-设置渠道vip");
		try {
			
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int agentid = DGUserCallService.UserCreateCall(usercreateBean2);
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			
			List<createmchBean>  createBean= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid);
			GodmchManageCallService.createmchCallForChannel(createBean.get(0));
			
			bean.setMchId(ccbean.getMchId());
			bean.setVipFlag(true);
			
			call.setData(bean);
			call.callService();			
			//mch_info
			Map<String, Object> map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			Logger.verifyEquals(1, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip=1");
			//mch_relation
			mch_relation mchrelation = mchrelationWapper.selectByPrimaryKey(agentid, ccbean.getMchId()).get(0);
			Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证AddSubAgent");
			
			// agent_type
			//渠道
			Map<String, Object> map2 = new HashMap();
			map2.put("mchId", ccbean.getMchId());
			List<agent_type> agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			//vipvip代理
			Map<String, Object> map3 = new HashMap();
			map3.put("mchId", agentid);
			agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setVipChannel_002_1() {
		Logger.start(true,"正例-设置vip渠道商标识-渠道-设置渠道vip-创建代理");
		try {
			
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int agentid = DGUserCallService.UserCreateCall(usercreateBean2);
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			
            Logger.comment("mchId:"+ccbean.getMchId());
            Logger.comment("agentid:"+agentid);
            
			bean.setMchId(ccbean.getMchId());
			bean.setVipFlag(true);
			call.setData(bean);
			call.callService();
			
			List<createmchBean>  createBean= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid);
			GodmchManageCallService.createmchCallForChannel(createBean.get(0));
			
			//mch_info
			Map<String, Object> map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			Logger.verifyEquals(1, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip=1");
			//mch_relation
			mch_relation mchrelation = mchrelationWapper.selectByPrimaryKey(agentid, ccbean.getMchId()).get(0);
			Logger.verifyEquals(1, mchrelation.getAddSubAgent(), "验证AddSubAgent");
			// agent_type
			//渠道
			Map<String, Object> map2 = new HashMap();
			map2.put("mchId", ccbean.getMchId());
			List<agent_type> agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			//vip代理
			Map<String, Object> map3 = new HashMap();
			map3.put("mchId", agentid);
			agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setVipChannel_003() {
		Logger.start(true,"正例-设置vip渠道商标识-有代理-设置代理vip");
		try {
			
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int agentid = DGUserCallService.UserCreateCall(usercreateBean2);
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			
			List<createmchBean>  createBean= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid);
			createBean.get(0).setCountry("CHN");
			GodmchManageCallService.createmchCallForChannel(createBean.get(0));
			
			bean.setMchId(agentid);
			bean.setVipFlag(true);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("商户不存在或非渠道商身份"), "验证msg");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setVipChannel_004() {
		Logger.start(true,"正例-设置vip渠道商标识-有代理-设置代理vip");
		try {
			
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int agentid = DGUserCallService.UserCreateCall(usercreateBean2);
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			
			List<createmchBean>  createBean= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid);
			GodmchManageCallService.createmchCallForChannel(createBean.get(0));
			
			bean.setMchId(ccbean.getMchId());
			bean.setVipFlag(true);
			call.setData(bean);
			call.callService();			
			
	     	bean.setVipFlag(false);
			call.setData(bean);
			call.callService();	
			//mch_info
			Map<String, Object> map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			Logger.verifyEquals(0, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip=1");
			//mch_relation
			mch_relation mchrelation = mchrelationWapper.selectByPrimaryKey(agentid, ccbean.getMchId()).get(0);
			Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证AddSubAgent");
			
			// agent_type
			//渠道
			Map<String, Object> map2 = new HashMap();
			map2.put("mchId", ccbean.getMchId());
			List<agent_type> agenttypeList = agenttypeWapper.selectby(map2);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			//vipvip代理
			Map<String, Object> map3 = new HashMap();
			map3.put("mchId", agentid);
			agenttypeList = agenttypeWapper.selectby(map3);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setVipChannel_005() {
		Logger.start(true,"正例-设置vip渠道商标识-代理 招代理-设置代理vip");
		try {
			
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int agentid = DGUserCallService.UserCreateCall(usercreateBean);
			
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int agentid2 = DGUserCallService.UserCreateCall(usercreateBean2);
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			//渠道-代理
			List<createmchBean>  createBean= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid);
			GodmchManageCallService.createmchCallForChannel(createBean.get(0));
			
			//代理-代理
			List<createmchBean>  createBean2= GodmchManageCallService.InitcreatemchBeanForAgent(agentid,agentid2);
			GodmchManageCallService.createmchCallForChannel(createBean2.get(0));
			
			bean.setMchId(ccbean.getMchId());
			bean.setVipFlag(true);
			call.setData(bean);
			call.callService();			
			
	     	bean.setVipFlag(false);
			call.setData(bean);
			call.callService();	
			Logger.comment("ccbean.getMchId():"+ccbean.getMchId());
			Logger.comment("agentid:"+agentid);
			Logger.comment("agentid2:"+agentid2);
			
			//mch_info
			Map<String, Object> map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			Logger.verifyEquals(0, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip=1");
			//mch_relation 代理1
			mch_relation mchrelation = mchrelationWapper.selectByPrimaryKey(agentid, ccbean.getMchId()).get(0);
			Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证代理1AddSubAgent");
			//mch_relation 代理2
			mchrelation = mchrelationWapper.selectByPrimaryKey(agentid2,agentid).get(0);
			Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证代理2AddSubAgent");
			// agent_type
			//渠道
			Map<String, Object> map2 = new HashMap();
			map2.put("mchId", ccbean.getMchId());
			List<agent_type> agenttypeList = agenttypeWapper.selectby(map2);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			//vip代理1
			Map<String, Object> map3 = new HashMap();
			map3.put("mchId", agentid);
			agenttypeList = agenttypeWapper.selectby(map3);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			
			//vip代理2
			Map<String, Object> map4 = new HashMap();
			map4.put("mchId", agentid2);
			agenttypeList = agenttypeWapper.selectby(map4);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 二级代理 字段agentType 存在");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setVipChannel_006() {
		Logger.start(true,"正例-设置vip渠道商标识-代理 招代理-设置代理vip");
		try {
			
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int agentid = DGUserCallService.UserCreateCall(usercreateBean);
			
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int agentid2 = DGUserCallService.UserCreateCall(usercreateBean2);
			
			UserCreateBean usercreateBean3 = DGUserCallService.initSellerUsercreateBean();
			int agentid3 = DGUserCallService.UserCreateCall(usercreateBean3);
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			//渠道-代理1
			List<createmchBean>  createBean= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid);
			GodmchManageCallService.createmchCallForChannel(createBean.get(0));
			//渠道-代理11
			List<createmchBean>  createBean3= GodmchManageCallService.InitcreatemchBeanForAgent(ccbean.getMchId(), agentid3);
			GodmchManageCallService.createmchCallForChannel(createBean3.get(0));
			//代理1-代理2
			List<createmchBean>  createBean2= GodmchManageCallService.InitcreatemchBeanForAgent(agentid,agentid2);
			GodmchManageCallService.createmchCallForChannel(createBean2.get(0));
			
			bean.setMchId(ccbean.getMchId());
			bean.setVipFlag(true);
			call.setData(bean);
			call.callService();			
			
	     	bean.setVipFlag(false);
			call.setData(bean);
			call.callService();	
			
			Logger.comment("ccbean.getMchId():"+ccbean.getMchId());
			Logger.comment("agentid:"+agentid);
			Logger.comment("agentid2:"+agentid2);
			Logger.comment("agentid3:"+agentid3);
			
			//mch_info
			Map<String, Object> map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			Logger.verifyEquals(0, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip=1");
			//mch_relation 代理1
			mch_relation mchrelation = mchrelationWapper.selectByPrimaryKey(agentid, ccbean.getMchId()).get(0);
			Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证代理1AddSubAgent");
			//mch_relation 代理2
			mchrelation = mchrelationWapper.selectByPrimaryKey(agentid3,ccbean.getMchId()).get(0);
			Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证代理2AddSubAgent");
			//mch_relation 代理3
			mchrelation = mchrelationWapper.selectByPrimaryKey(agentid2,agentid).get(0);
			Logger.verifyEquals(0, mchrelation.getAddSubAgent(), "验证代理3AddSubAgent");
			// agent_type
			//渠道
			map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			List<agent_type> agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			//vip代理1
			map = new HashMap();
			map.put("mchId", agentid);
			agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
			//vip代理2
			map= new HashMap();
			map.put("mchId", agentid2);
			agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 二级代理1 字段agentType 存在");
			//vip代理2
			map= new HashMap();
			map.put("mchId", agentid3);
			agenttypeList = agenttypeWapper.selectby(map);
			Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 二级代理2 字段agentType 存在");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}